# -*- coding: UTF-8 -*-
# Author: Damon(wuud1)
# CreateDate: 
# Message: 清洗过程中用到的工具

try:
    from functools import reduce
except :
    import reduce
import json
import re
def myfunc(lists):
    # list all possible composition from many list, each item is a tuple.
    # Here lists is [list1, list2, list3], return a list of [(item1,item2,item3),...]
    # len of result list and result list.
    total = reduce(lambda x, y: x * y, map(len, lists))
    retList = []
    # every item of result list.
    for i in range(0, total):
        step = total
        tempItem = []
        for l in lists:
            step /= len(l)
            tempItem.append(l[int(i / step % len(l))])
        retList.append('.'.join(tempItem))
    return retList

def clean(raw):
    '''把字符串转换成对应的条件组合,输出所有条件组合set
    涉及变量太多,不想起名'''
    t_l = re.findall('\(.*?\)', raw)
    # print(t_l)
    for t in t_l:
        i = t.replace('+', '*')
        # print(i)
        raw = raw.replace(t, i)
    # print(raw)
    raw_l = raw.split('+')
    # print(raw_l)
    _l = []
    for i in raw_l:
        # S.(GEN*GCC).QG16.(PE*SE).(MT*AT)
        i_k = re.findall('\(.*?\)', i)
        # print("ik",i_k)
        if len(i_k)>1:
            # ['(GEN*GCC)', '(PE*SE)', '(MT*AT)']
            l = []
            k = [i.replace('(','').replace(')','').split('*') for i in i_k]
            m = myfunc(k)
            i_q = i
            for n in i_k:
                i_q = i_q.replace(n, '')
            i_q = i_q.replace(' ', '').replace('..','.')
            for o in m:
                r = (i_q+'.'+o).replace(' ', '').replace('..','.').replace('..','.')
                _l.append(r)
        else:
            if not i_k:
                _l.append(i.replace(' ', '').replace('..','.').replace('..','.'))
                continue
            i_q = i.replace(i_k[0], '').replace('..', '.')

            i_l = i_k[0].replace('(', '').replace(')', '')
            i_l = i_l.split("*")
            for j in i_l:
                r = (i_q+'.'+j).replace(' ', '').replace('..','.').replace('..','.')
                _l.append(r)
    # print(_l)
    return _l

if __name__ == '__main__':
    raw = ''
    res = clean(raw)
    print(res)
